package com.hmall.api.client;

import com.hmall.api.client.fallback.ItemClientFallback;
import com.hmall.api.config.DefaultFeignConfig;
import com.hmall.api.domain.dto.ItemDTO;
import com.hmall.api.domain.dto.OrderDetailDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

//fallback作用是当远程调用失败时，会调用fallback指定的类中的方法 configuration指定配置类
@FeignClient(value = "item-service", fallbackFactory = ItemClientFallback.class,
        configuration = DefaultFeignConfig.class)
//远程连接日志局部只针对调用当前这个服务
//@FeignClient(value = "item-service", configuration = DefaultFeignConfig.class)
//这个注解的作用是告诉SpringCloud这个接口是一个远程客户端，要调用服务名为item-service的服务
//@RequestMapping("/items") @RequestMapping annotation not allowed on @FeignClient interfaces
public interface ItemClient {
    @GetMapping("items")//FeignBlockingLoadBalancerClient实现
    List<ItemDTO> queryItemByids(@RequestParam("ids")Collection<Long> ids);
    @PutMapping("items/stock/deduct")
    void deductStock(@RequestBody List<OrderDetailDTO> items);
    @GetMapping("items/{id}")
    ItemDTO queryItemById(@PathVariable("id") Long id);
    @PutMapping("items/stock/restore")
    void restoreStock(@RequestBody List<OrderDetailDTO> items);

}
